package ch07_GUI编程;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EventModelDemo implements ActionListener {
	JLabel tip = new JLabel("请单击下面的按钮");
	JButton b1 = new JButton("确定");
	JButton b2 = new JButton("取消");

	public static void main(String[] args) {
		new EventModelDemo().init();
	}

	void init() {
		BaseFrame f = new BaseFrame("EventModel Demo");
		f.setLayout(new FlowLayout());

		b1.addActionListener(this);
		b2.addActionListener(this);

		f.add(tip);
		f.add(b1);
		f.add(b2);
		f.showMe();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == b1) {
			tip.setText("你单击了[" + b1.getText() + "]按钮");
		} else if (e.getSource() == b2) {
			tip.setText("你单击了[" + b2.getText() + "]按钮");
		}

	}
}
